1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5
6 public class Spawner : MonoBehaviour {
7
8 public GameObject pin;
9 public int maxPin;
10
11 [HideInInspector]
12 public int totalPin;
13
14 [HideInInspector]
15 public int limitPin;
16
17 private Text countText;
18
19 void Awake(){
20 totalPin = maxPin;
21 }
22
23 // Use this for initialization
24 void Start () {
25 InitializeSpawnVariables ();
26 }
27
28 // Update is called once per frame
29 void Update () {
30
31 }
32
33 void InitializeSpawnVariables(){
34 limitPin = 4;
35
36 Vector3[] pinPosition = new[] {
37 new Vector3(0, -2.0f, 0),
38 new Vector3(0, -2.8f, 0),
39 new Vector3(0, -3.6f, 0),
40 new Vector3(0, -4.4f, 0)
41 };
42
43 for (int i = 0; i < limitPin; i++) {
44 if(maxPin != 0){
45 GameObject newPin = Instantiate (pin, pinPosition [i], Quaternion.identity) as GameObject;
46 if (i == 0)
47 newPin.transform.GetComponent<Pin> ().isPrepareToShoot = true;
48
49 countText = newPin.transform.GetChild (1).gameObject.transform.GetChild (0).gameObject.GetComponent<Text> ();
50 countText.text = maxPin.ToString ();
51 maxPin--;
52 }
53 }
54
55
56
57 }
58
59 public void IsPrepareToFire(){
60 int index = 0;
61 Vector3[] pinPosition = new[] {
62 new Vector3 (0, -2.0f, 0),
63 new Vector3 (0, -2.8f, 0),
64 new Vector3 (0, -3.6f, 0)
65 };
66 GameObject[] nextPin = GameObject.FindGameObjectsWithTag("Pin");
67 foreach(GameObject newPin in nextPin){
68 if(!newPin.transform.GetComponent<Pin>().hasMove){
69 newPin.transform.position = Vector3.Lerp (newPin.transform.position, pinPosition [index], Time.time);
70 if(index == 0){
71 newPin.transform.GetComponent<Pin> ().isPrepareToShoot = true;
72 }
73 index++;
74
75 }
76
77 }
78
79 if(maxPin != 0){
80 GameObject newPin = Instantiate (pin, new Vector3(0, -4.4f, 0), Quaternion.identity) as GameObject;
81 countText = newPin.transform.GetChild (1).gameObject.transform.GetChild (0).gameObject.GetComponent<Text>();
82 countText.text = maxPin.ToString ();
83
84 maxPin--;
85 }
86
87
88 }
89
90
91
92 }